package com.chaos.eurekaproducer.leetCode.sort;

/**
 * @author liaopeng
 * @title: Sort1
 * @projectName eureka-producer
 * @description: 冒泡排序
 * @date 2021/7/5下午3:56
 */
public class BubbleSort {

    public static int[] bubbleSort(int[] a){
        if (a.length==0){
            return a;
        }
        for (int i = 0; i < a.length; i++) {
            for (int j = i+1; j < a.length; j++) {
                if (a[i]>a[j]){
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        return a;
    }

    public static void main(String[] args) {
        int[] a = new int[]{3,4,6,1,2};
        int[] b = bubbleSort(a);
        for (int i = 0; i < b.length; i++) {
            int i1 = b[i];
            System.out.println(i1);
        }
    }
}
